﻿<%@ WebHandler Language="C#" Class="getCommentByRIdHandler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using System.IO;
using System.Runtime.Serialization.Json;

public class getCommentByRIdHandler : IHttpHandler
{
    
    public void ProcessRequest (HttpContext context) {
        int RId = 0;
        RId = int.Parse(context.Request.QueryString["RId"]);
        RtypeEntity model;
        List<RtypeEntity> list = new List<RtypeEntity>();


        string str = System.Configuration.ConfigurationManager.ConnectionStrings["decheatConnectionString"].ToString();
        string sql = "SELECT top 3 [R_content], [R_type], [IP_from] FROM [Dyh_report] WHERE ([seqID] = " + RId + ") ORDER BY [time]";
        SqlConnection conn = new SqlConnection(str);
        conn.Open();
        SqlCommand comm = new SqlCommand(sql, conn);
        System.Data.DataSet ds = new DataSet();
        SqlDataReader dr = comm.ExecuteReader();
        while (dr.Read())
        {

            string name = dr["IP_from"].ToString();
            string r_content = dr["R_content"].ToString();
            Console.WriteLine(name + ":" + r_content);
            model = new RtypeEntity(0, name, r_content);
            list.Add(model);
        }
        //JsonHelper.GetJson<List<Tongji>

        dr.Close();
        if (conn.State == ConnectionState.Open)
        {
            conn.Close();
        }
        //JavaScriptSerializer json = new JavaScriptSerializer();
        string result = WebUI.CommonClass.JSONHelper.Obj2Json<List<RtypeEntity>>(list);
        context.Response.ContentType = "text/plain";
        context.Response.Write(result);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}